﻿Imports 坐标转换类

Public Class 多点拟合圆

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim bs As New BindingSource
        'bs.DataSource = dt
        'grd.DataSource = bs

        'SetParent(Me.Handle, FindWindow("Progman", "Program Manager"))



        grd.Rows.Add(4)
        grd.Rows(0).Cells(0).Value = -224.866
        grd.Rows(0).Cells(1).Value = -79.662
        grd.Rows(1).Cells(0).Value = -185.952
        grd.Rows(1).Cells(1).Value = -65.242
        grd.Rows(2).Cells(0).Value = -128.787
        grd.Rows(2).Cells(1).Value = -119.025
        grd.Rows(3).Cells(0).Value = -131.318
        grd.Rows(3).Cells(1).Value = -140.636
        'grd.Rows(4).Cells(0).Value = 360
        'grd.Rows(4).Cells(1).Value = 272


    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Circle1 As CoordTrans.Circle
        'Dim X, Y, R As Single
        Dim pointNo As Integer
        pointNo = grd.RowCount - 1
        Dim pPointList As New List(Of PointF)


        For i = 0 To pointNo - 1
            Dim P1 As New PointF
            P1.x = grd.Rows(i).Cells(0).Value
            P1.y = grd.Rows(i).Cells(1).Value
            pPointList.Add(P1)
        Next

        Circle1 = CoordTrans.FittingCircle(pPointList)

        X_Num.Value = Circle1.X
        Y_Num.Value = Circle1.Y
        Angel_Num.Value = Circle1.R
    End Sub
End Class
